<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/css/styletable.css" type="text/css"/>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <script src="/layui/layui.all.js" charset="utf-8"></script>
    <script src="/js/jquery.2.1.4.js" charset="utf-8"></script>
    <script type="text/javascript" src="/raty/demo/js/jquery.min.js"></script>
    <script type="text/javascript" src="/raty/lib/jquery.raty.min.js"></script>
<body>

<script>
    function edit() {
        if ($(".check:checked").size() != 1) {
            layer.alert('请选择一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            $("#probform").attr("action", "/prob/toedit").submit();
        }
    }

    function detail(th) {
        var prob;
        var pid = $(th).parent().prevAll(".pid").children().val();
        var ptitle = $(th).parent().prevAll(".ptitle").html();
        layer.open({
            title:ptitle,
            type: 2,
            area: ['85%', '85%'],
            content: '/prob/detail/' + pid
        });
        return false;
    }

    function append(th) {
        var message ='<div style="margin: 0px" class="layui-input-block">\n' +
            '            <textarea id="textcontent" rows="7" cols="15" style="margin: 0px 5px 0px 5px;" name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>\n' +
            '          </div>';
        var pid = $(th).parent().prevAll(".pid").children().val();
            layer.open({
                title: '补充内容'
                ,area: ['45%', '50%']
                , content: message
                , yes: function (index, layero) {
                    var text = $("#textcontent").val();
                    text0 = text.split("\n").join("<br>");
                    if (text0.length != 0){
                    window.location.href = "/prob/append/" + pid + "/" + text0;
                    }
                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                }
            });
            return false
    }

    function score(th) {
        var pid = $(th).parent().prevAll(".pid").children().val();
        layer.open({
            title: '问题评分'
            ,type: 2
            ,btn: ['打分']
            ,area: ['30%', '40%']
            , content: '/page/score.jsp'
            , yes: function (index, layero) {
                var frame = $(layero).find("iframe");
                var raty = frame.contents().find("#scorevalue").val();
                window.location.href = "/prob/score/" + raty + "/" + pid;
                layer.close(index);
            }
        });
        return false
    }
</script>

<div style="margin: 10px 15px 0px 15px">
    <div style="margin-top: 1px;margin-left: 1px;margin-bottom: 8px">
        <a class="layui-btn layui-btn-normal" href="/prob/toadd">添加</a>
        <button class="layui-btn layui-btn-edit" onclick="edit();">编辑</button>
    </div>
    <form id="probform">
        <input id="contentid" type="hidden">
        <table style="width: 100%">

            <tr>
                <th width="5%"></th>
                <th width="35%">标题</th>
                <th width="25%">创建时间</th>
                <th width="15%">状态</th>
                <th width="20%">操作</th>
            </tr>

            <c:forEach items="${probs}" var="prob">
                <tr>
                    <td class="pid" align="center"><input class="check" name="checks" value="${prob.pid}"
                                                              type="checkbox"/></td>
                    <td class="ptitle">${prob.ptitle}</td>
                    <td>${prob.pdate}</td>
                        <%--<td>${prob.pstate}</td>--%>
                    <td align="center"><span class="layui-btn layui-btn-mini
                    <c:if test="${prob.pstate=='已结束'}">layui-btn-warm</c:if>">${prob.pstate}</span>
                    </td>
                    <td align="center">
                        <button class="layui-btn layui-btn-small layui-btn-delete" onclick="return detail(this);">查看详情
                        </button>&nbsp;
                        <c:if test="${prob.pstate=='进行中'}">
                        <button class="layui-btn layui-btn-small layui-btn-append" onclick="return append(this);">补充</button>
                        </c:if>
                        <c:if test="${prob.pstate=='已结束'}">
                            <button class="layui-btn layui-btn-small layui-btn-score" onclick="return score(this);">打分</button>
                        </c:if>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </form>
</div>
</body>
</html>
